//
//  TweetViewModel.m
//  OSChina
//
//  Created by 8b410-2 on 16/12/26.
//  Copyright © 2016年 abb. All rights reserved.
//

#import "OSCTweetViewModel.h"

@implementation OSCTweetViewModel

- (instancetype)initWithModel:(OSCTweet *)model {
    if (self = [super init]) {
        _author = model.author;
        _iconStr = model.portrait;
        _commentCount = [NSString stringWithFormat:@" %zd ",model.commentCount ];
        _idField = model.idField;
        _pubDate = model.pubDate;
        _imgBigURLArr = [self handleImageString:model.imgBig];
        _imgSmallURLArr = [self handleImageString:model.imgSmall];
        _content = [self handleHTMLSting:model.body];
    }
    return self;
}

/**
 处理多图字符串

 @param imageStr 多图字符串
 @return 图片地址数组
 */
- (NSArray *)handleImageString:(NSString *)imageStr {
    NSInteger imageURLLoc = [imageStr rangeOfString:imageBaseURL].length;
    NSString * imagePathStr = [imageStr substringFromIndex:imageURLLoc];
    NSArray *imagePaths = [imagePathStr componentsSeparatedByString:@","];
    NSMutableArray *imageURLs = [NSMutableArray arrayWithCapacity:imagePaths.count];
    [imagePaths enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [imageURLs addObject:[imageBaseURL stringByAppendingString:obj]];
    }];
    return imageURLs;
}

@end
